//
//  SearchResultViewController.m
//  CP20180523
//
//  Created by apple on 2018/5/27.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "SearchResultViewController.h"

@interface SearchResultViewController ()
@property (weak, nonatomic) IBOutlet UILabel *showDetailLabel;
@property (weak, nonatomic) IBOutlet UIView *numberBoxView;

@end

@implementation SearchResultViewController{
    CallBackBlock callBlock;
    NSDictionary* showDic;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.layer.cornerRadius = 7;
    self.view.layer.masksToBounds = YES;
    
    
    [self setShowDetail];
}

-(void)setShowDetail{
    NSArray* numberArray = showDic[@"kArray"];
    NSString* showString = showDic[@"kString"];
    
    self.showDetailLabel.text = showString;
    CGFloat ballWidth = 32;
    CGFloat spacing = 11;
    CGFloat spacingX = 0;
    for (int i=0; i<[numberArray count]; i++) {
        UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(ballWidth+spacing), 0, ballWidth, ballWidth)];
        numberView.backgroundColor = [UIColor whiteColor];
        UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ballWidth, ballWidth)];
        numberLabel.font = [UIFont boldSystemFontOfSize:15];
        numberLabel.textColor = kRGBColor(16,147,255);
        numberLabel.textAlignment = NSTextAlignmentCenter;
        numberLabel.text = [numberArray objectAtIndex:i];
        [numberView addSubview:numberLabel];
        numberView.layer.cornerRadius = ballWidth*0.5;
        [self.numberBoxView addSubview:numberView];
        spacingX+=(ballWidth+spacing);
    }
    
}

-(void)searchResultWith:(NSDictionary*)resultDic andCallBack:(CallBackBlock)callBack{
    
    showDic = resultDic;
    if (callBack) {
        callBlock = callBack;
    }
}

#pragma mark - 选号
- (IBAction)nextAction:(id)sender {
    NSArray* numberArray = showDic[@"kArray"];
    [[NSUserDefaults standardUserDefaults] setObject:numberArray forKey:@"kOfLocal11X5Number"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    if (callBlock) {
        callBlock(YES);
    }
}

#pragma mark - 再次查询
- (IBAction)searchAgain:(id)sender {
    if (callBlock) {
        callBlock(NO);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
